package base

import (
	"fmt"
	"sync"
)

func UseWaitGroup()  {
	var wg sync.WaitGroup
	num := int32(0)
	fmt.Printf("num = %d \n", num)
	wg.Add(2)
	defer wg.Wait()
	go addNum(&num, 1, wg.Done)
	go addNum(&num, 2, wg.Done)
}

func addNum(num *int32, val int32, fn func()) {
	*num += val
	fmt.Printf("addNum num = %d \n", *num)
	fn()
}